package com.grsu.phonestation.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.grsu.phonestation.dao.InvoiceDAO;
import com.grsu.phonestation.dao.impl.base.AbstractHibernateDAO;
import com.grsu.phonestation.domain.Client;
import com.grsu.phonestation.domain.Invoice;

@Repository
public class InvoiceDAOImpl extends AbstractHibernateDAO<Invoice, Integer>
		implements InvoiceDAO {

	@Override
	public Invoice findById(Integer invoiceId) {
		Criteria criteria = getSession().createCriteria(Invoice.class).add(
				Restrictions.eq("id", invoiceId));
		return (Invoice) criteria.uniqueResult();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Invoice> getInvoicesClient(Client client) {
		Criteria criteria = getSession().createCriteria(Invoice.class).add(
				Restrictions.eq("user", client));
		List<Invoice> invoices = criteria.list();
		return invoices;
	}

}
